package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsUserMapper;
import com.qf.mapper.StatMapper;
import com.qf.pojo.DtsUser;
import com.qf.service.DtsUserService;
import com.qf.vo.DayStatis;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @author Administrator
 * @version v1.0
 * @date 2022/5/18
 */
@Service
public class DtsUserServiceImpl implements DtsUserService {
    @Autowired
    DtsUserMapper userMapper;
    @Autowired
    StatMapper statMapper;
    @Override
    public Integer getTotal() {
        return userMapper.selectCount(null);
    }

    @Override
    public List<DayStatis> findUserStatis() {
        return statMapper.getUserCnts();
    }

    @Override
    public IPage<DtsUser> selectPage(Integer page, Integer limit, String username, String mobile, String sort, String order) {
        IPage<DtsUser> iPage = new Page<>(page, limit);
        QueryWrapper<DtsUser> qw = new QueryWrapper<>();

        if(!StringUtils.isEmpty(username)){
            qw.like("username", username);
        }
        if(!StringUtils.isEmpty(mobile)){
            qw.like("mobile", mobile);
        }
        if(!StringUtils.isEmpty(sort)&&!StringUtils.isEmpty(order)){
            if("desc".equals(order)){
                qw.orderByDesc(sort);
            }else{
                qw.orderByAsc(sort);
            }
        }
        userMapper.selectPage(iPage, qw);
        return iPage;
    }
}
